package ce.com.cenewbluesdk.entity.k3;

import android.os.Parcel;
import android.os.Parcelable;

import ce.com.cenewbluesdk.CEBC;
import ce.com.cenewbluesdk.entity.BaseData;
import ce.com.cenewbluesdk.entity.CEDevData;

/**
 * Created by Administrator on 2015/7/3.
 * typedef struct
 * {
 * unsigned char	weather;		//天气类型，0：晴天；1：阴天；2：下雨；3：其它
 * unsigned char temperature_sig;  //0: + ; 1:-
 * unsigned char	temperature[2];  //温度，精确到小数到后一位；
 * }weather_info_struct;
 */
public class Send_Weather_Struct_K3 extends BaseData implements Parcelable {

    public static final byte WEATHER_SUNNLY = 0;
    public static final byte WEATHER_CLOUDY = 1;
    public static final byte WEATHER_RAIN = 2;
    public static final byte WEATHER_OTHER = 3;

    public static final byte POSITION_VALUE = 0;
    public static final byte NEGATIVE_VALUE = 1;

    byte weather;
    byte temp_sig;
    byte temp_value_low;

    byte temp_sig_high;
    byte temp_value_high ;

    byte pm1; //  这个是要除256 取于
    byte pm2;   //  这个是要除256 取商

    public Send_Weather_Struct_K3(byte weatherType, byte temp_sig_low, int tempera_low, byte temp_sig_high, int tempera_high,
                                  int pm) {
        this.weather = weatherType;
        this.temp_sig = temp_sig_low;
        this.temp_value_low= (byte) tempera_low;


        this.temp_sig_high=temp_sig_high;
        this.temp_value_high= (byte) tempera_high;


        pm1= (byte) (pm%256);
        pm2= (byte) (pm/256);


    }

    protected Send_Weather_Struct_K3(Parcel in) {
        weather = in.readByte();
        temp_sig = in.readByte();
        temp_value_low = in.readByte();
        temp_sig_high = in.readByte();
        temp_value_high = in.readByte();
        pm1 = in.readByte();
        pm2 = in.readByte();
    }

    public static final Creator<Send_Weather_Struct_K3> CREATOR = new Creator<Send_Weather_Struct_K3>() {
        @Override
        public Send_Weather_Struct_K3 createFromParcel(Parcel in) {
            return new Send_Weather_Struct_K3(in);
        }

        @Override
        public Send_Weather_Struct_K3[] newArray(int size) {
            return new Send_Weather_Struct_K3[size];
        }
    };

    public byte[] getBytes() {
        byte[] bytes = new byte[7];
        bytes[0] = weather;
        bytes[1] = temp_sig;
        bytes[2] = temp_value_low;
        bytes[3] = temp_sig_high;
        bytes[4] = temp_value_high;
        bytes[5] = pm1;
        bytes[6] = pm2;


        return bytes;
    }

    public static int getItemSize() {
        return 7;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte(weather);
        dest.writeByte(temp_sig);
        dest.writeByte(temp_value_low);
        dest.writeByte(temp_sig_high);
        dest.writeByte(temp_value_high);
        dest.writeByte(pm1);
        dest.writeByte(pm2);
    }

    @Override
    public CEDevData toCEDevData() {
        CEDevData data=new CEDevData();
        data.setCmd(CEBC.CMD_SEND_TYPE);
        data.setDataType(CEBC.K3.DATA_TYPE_WEATHER);
        data.setData(getBytes());
        data.setItemL(getItemSize());
        data.setItemNumber(1);
        return data;
    }
}
